﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace AerolionMVC.Models
{
    public interface IFlightRepository
    {
        IQueryable<Flight> FindAllFlights();
        Flight GetFlight(string id);
        void Add(Flight flight);
        void Delete(Flight flight);
        void Save();
    }
    public class FlightRepository : IFlightRepository
    {
        
        private AerolionMVCEntities db = new AerolionMVCEntities();
        public IQueryable<Flight> FindAllFlights()
        {
            return db.Flights;
        }
        
        public virtual Flight GetFlight(string id)
        {
            
            return db.Flights.SingleOrDefault(d => d.FlightId == id);
        }

        public virtual void Add(Flight flight)
        {

            db.AddToFlights(flight);
        }

        public virtual void Delete(Flight flight)
        {
            db.DeleteObject(flight);
           
        }

        public virtual void Save()
        {
            db.SaveChanges();
        }
    }

}
